/* =====================================================================================
/   TABLE: Polls
/  ===================================================================================== */

if exists (select * from [dbo].sysobjects where id = object_id(N'[dbo].[Polls]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Polls]

GO

CREATE TABLE [dbo].[Polls](
	[Id] [uniqueidentifier] NOT NULL,
	[PageContentId] [int] NOT NULL,
	[Question] [nvarchar](max) COLLATE Ukrainian_CI_AS NOT NULL,
	[Activated] [bit] NOT NULL,
	[ExpirationDate] [datetime] NULL,
	[CreatedBy] [int] NULL,
	[CreatedDate] [datetime] NOT NULL,
	[ModifiedBy] [int] NULL,
	[ModifiedDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Polls] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[Polls]  WITH CHECK ADD  CONSTRAINT [FK_Polls_PageContents] FOREIGN KEY([PageContentId])
REFERENCES [dbo].[PageContents] ([Id])
GO
ALTER TABLE [dbo].[Polls] CHECK CONSTRAINT [FK_Polls_PageContents]
GO
ALTER TABLE [dbo].[Polls]  WITH CHECK ADD  CONSTRAINT [FK_Polls_Users] FOREIGN KEY([ModifiedBy])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[Polls] CHECK CONSTRAINT [FK_Polls_Users]
GO
ALTER TABLE [dbo].[Polls]  WITH CHECK ADD  CONSTRAINT [FK_Polls_Users0] FOREIGN KEY([CreatedBy])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[Polls] CHECK CONSTRAINT [FK_Polls_Users0]

GO


/* =====================================================================================
/   TABLE: [PollAnswers]
/  ===================================================================================== */

if exists (select * from [dbo].sysobjects where id = object_id(N'[dbo].[PollAnswers]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[PollAnswers]

GO


CREATE TABLE [dbo].[PollAnswers](
	[Id] [uniqueidentifier] NOT NULL,
	[PollId] [uniqueidentifier] NOT NULL,
	[Answer] [nvarchar](max) COLLATE Ukrainian_CI_AS NOT NULL,
	[Vote] [int] NOT NULL,
	[CreatedBy] [int] NULL,
	[CreatedDate] [datetime] NOT NULL,
	[ModifiedBy] [int] NULL,
	[ModifiedDate] [datetime] NOT NULL,
 CONSTRAINT [PK_PollAnswer] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[PollAnswers]  WITH CHECK ADD  CONSTRAINT [FK_PollAnswer_Polls] FOREIGN KEY([PollId])
REFERENCES [dbo].[Polls] ([Id])
GO
ALTER TABLE [dbo].[PollAnswers] CHECK CONSTRAINT [FK_PollAnswer_Polls]
GO
ALTER TABLE [dbo].[PollAnswers]  WITH CHECK ADD  CONSTRAINT [FK_PollAnswer_Users] FOREIGN KEY([CreatedBy])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[PollAnswers] CHECK CONSTRAINT [FK_PollAnswer_Users]
GO
ALTER TABLE [dbo].[PollAnswers]  WITH CHECK ADD  CONSTRAINT [FK_PollAnswer_Users1] FOREIGN KEY([ModifiedBy])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[PollAnswers] CHECK CONSTRAINT [FK_PollAnswer_Users1]

GO
